package com.gitee.minimalismstyle.fresh.common.core.validate

class LengthValueValidate : ValueValidate {

    override fun check(value: Any?, params: String?): ValidateResult {
        return if(value == null || value.equals("")){
            ValidateResult(true)
        } else {
            val length = value.toString().length
            val minmax = params!!.split(",")
            val minlength = minmax[0].toInt()
            val maxlength = minmax[1].toInt()
            if(length < minlength){
                ValidateResult(false, "长度不能小于${minlength}")
            }else if(length > maxlength){
                ValidateResult(false, "长度不能大于${maxlength}")
            }else{
                ValidateResult(true)
            }
        }
    }
}